//
//  KDBaseTool.m
//  警用舆情平台
//
//  Created by 魏强 on 15/5/27.
//  Copyright (c) 2015年 魏强. All rights reserved.
//

#import "KDBaseTool.h"
#import "MJExtension.h"
@implementation KDBaseTool
+ (void)get:(NSString *)url param:(id)param resultClass:(Class)resultClass  success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure
{
    NSDictionary *params = [param keyValues];
     KDLog(@"%@", params);
    [KDHttpTool get:url parameters:params success:^(id responseObj) {
        if (success) {
//            KDLog(@"%@", responseObj);
            id result = [resultClass objectWithKeyValues:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
+ (void)post:(NSString *)url param:(id)param resultClass:(Class)resultClass  success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure
{
    NSDictionary *params = [param keyValues];
    KDLog(@"%@", params);
    [KDHttpTool post:url parameters:params success:^(id responseObj) {
        if (success) {
//            KDLog(@"%@", responseObj);
            id result = [resultClass objectWithKeyValues:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
//            KDLog(@"%@", error.JSONString);
        }
    }];
}

+ (void)post:(NSString *)url bodyJson:(id)param resultClass:(Class)resultClass  success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure
{
    //NSDictionary *params = [param keyValues];
    KDLog(@"%@", param);
    [KDHttpTool post:url bodyJson:param success:^(id responseObj) {
        if (success) {
            //            KDLog(@"%@", responseObj);
            id result = [resultClass objectWithKeyValues:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
            //            KDLog(@"%@", error.JSONString);
        }
    }];
}
+ (void)post:(NSString *)url param:(id)param resultClass:(Class)resultClass  constructingBodyWithBlock:(void(^)(id<AFMultipartFormData> formData))imageblock success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure
{
    NSDictionary *params = [param keyValues];
    [KDHttpTool post:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        imageblock(formData);
    } success:^(id responseObj) {
        if (success) {
            id result = [resultClass objectWithKeyValues:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
+ (void)put:(NSString *)url param:(id)param resultClass:(Class)resultClass  success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure{
    NSDictionary *params = [param keyValues];
    KDLog(@"%@", params);
    [KDHttpTool put:url parameters:params success:^(id responseObj) {
        if (success) {
            //            KDLog(@"%@", responseObj);
            id result = [resultClass objectWithKeyValues:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
            //            KDLog(@"%@", error.JSONString);
        }
    }];
}
@end
